﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;
using LTJ.FrameWork;

namespace LTJ.WebPage.UserManage.system
{
    public partial class changepass : UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void updatepass_Click(object sender, EventArgs e)
        {
            string opwd = ypass.Text.Trim();
            string npwd = npass.Text.Trim();

            if (Users.CheckPassword(username, opwd, true) < 0)
            {
                base.RegisterStartupScript("PAGETEMPLATE", "原密码错误！");
            }            
            else if (!Utils.StrIsNullOrEmpty(ypass.Text) && npass.Text == rpass.Text)
            {
                userinfo.pass = LTJ.Common.Utils.MD5(npwd);
                bool msg = Users.UpdateUser(userinfo);
                if (msg)
                {
                    OpLogs.CreateCompanyOPLog(userinfo, SASRequest.GetIP(), LTJ.Entity.OpAction.ChangePass.ActionID, "");
                    base.RegisterStartupScript("PAGE", "window.location.href = '" + config.UserManagerUrl + "index.aspx';");
                }
                else
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "更新失败！");
                }
            }
            else
            {
                base.RegisterStartupScript("PAGETEMPLATE", "新密码不能为空, 且两次输入的密码必须相同!");
            }
        }

        #region Web 窗体设计器生成的代码

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            updatepass.Click += new EventHandler(updatepass_Click);
        }

        #endregion
    }
}